package lxs.tool.liberator.common.base.result;

import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
public class Response {
    private Integer status;
    private String message;
    private Object data;
    private Integer code;

    private Response() {
    }
    public static Response getInstance() {
        return new Response();
    }

    public Response setMessage(String message) {
        this.message = message;
        return this;
    }

    public static Response send(Object v) {
        Response response = getInstance();
        response.setStatus(200).setMessage("请求成功").setData(v).setCode(0);
        return response;
    }

    public static Response success(String msg) {
        Response response = getInstance();
        response.setStatus(200).setMessage(msg).setData(null).setCode(0);
        return response;
    }

    public static Response success() {
        Response response = getInstance();
        response.setStatus(200).setMessage("操作成功").setData(null).setCode(0);
        return response;
    }

    public static Response failed(String msg) {
        Response response = getInstance();
        response.setStatus(400).setMessage(msg).setData(null).setCode(1);
        return response;
    }
    public static Response failed() {
        Response response = getInstance();
        response.setStatus(400).setMessage("操作失败").setData(null).setCode(1);
        return response;
    }
    public static Response error(String msg) {
        Response response = getInstance();
        response.setStatus(500).setMessage(msg).setData(null).setCode(2);
        return response;
    }
    public static Response error() {
        Response response = getInstance();
        response.setStatus(500).setMessage("系统错误").setData(null).setCode(2);
        return response;
    }
}
